package com.haircut.sys.controller.menu;

import cn.hutool.core.util.StrUtil;
import com.haircut.sys.service.menu.IMenuService;
import com.haircut.sys.service.role.IRoleService;
import com.haircut.sys.utils.user.SecurityUtils;
import com.haircut.sys.vo.menu.MenuListReqVo;
import com.haircut.sys.vo.menu.MenuListVo;
import com.haircut.sys.vo.menu.MenuTreeVo;
import com.haircut.sys.vo.user.LoginUserVo;
import com.modular.result.RspMessage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/b/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IRoleService roleService;

    /**
     * 查询角色列表
     */
    @ApiOperation(value = "查询角色列表")
    @PostMapping("findAll")
    public RspMessage<List<MenuListVo>> findAll(@RequestBody MenuListReqVo reqVo){
        return RspMessage.success(menuService.findAll(reqVo));
    }

    /**
     * 查询角色列表
     */
    @ApiOperation(value = "按照树形查询菜单信息")
    @GetMapping("menuTreeByRoleId")
    public RspMessage<List<MenuTreeVo>> menuTreeByRoleId(){

        LoginUserVo userVo = SecurityUtils.getLoginUser();
        String roleId = userVo.getRoleId();
        return RspMessage.success(roleService.menuTreeByRoleId(roleId));
    }
}
